<?php
/**
 * Created by PhpStorm.
 * User: 郑好
 * Date: 2019/7/4
 * Time: 下午3:15
 */

namespace app\common;

use think\Exception;

class LotteryGraph
{
    use InstanceTrait;

    private $lotteryDomain = "";

    protected function __construct()
    {
        if (env("APP_ENV") == "prod") {
            $this->lotteryDomain = "https://server.fu51.cn/";
        } elseif (env("APP_ENV") == "pre") {
            $this->lotteryDomain = "http://kaijiang-server-pre.fu51.cn/";
        } else {
            $this->lotteryDomain = "http://kaijiang-server-dev.fu51.cn/";
        }
    }

    private function doGet($route, $urlParams = [])
    {
        try {
            $headers = [
                "Origin-Secret" => md5("7e2p4db72dja-cmit-@GGWV#s-".date("Y-m-d")."-xmcmit")
            ];

            $url = $this->lotteryDomain . $route;

            $response = \app\common\Http::request($url, $headers, $urlParams, "GET", []);

            return $response->body;
        } catch (Exception $e) {
            \Log::error($e->getMessage());
        }
    }

    private function doPost($route, $params = [])
    {
        try {
            $headers = [
                "Origin-Secret" => md5("7e2p4db72dja-cmit-@GGWV#s-".date("Y-m-d")."-xmcmit")
            ];

            $url = $this->lotteryDomain . $route;

            $response = \app\common\Http::request($url, $headers, $params, "POST", []);

            return $response->body;
        } catch (Exception $e) {
            \Log::error($e->getMessage());
        }
    }

    public function getQgczByOptions($post)
    {
        $route = "graph/qgcz/get_by_options";

        $result = $this->doPost($route, $post);

        if (!$result) {
            return [
                "meta"=> [
                    "code" => _MSG_NOT_FOUND,
                    "msg" => "请求数据失败"
                ]
            ];
        }
        return json_decode($result, true);
    }
}
